/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import org.hibernate.Session;
import org.hibernate.Transaction;
import util.HibernateUtil;

/**
 *
 * @author Administrador
 */
public class DaoFactory {
   private final Session session;
   private Transaction transaction;
   public DaoFactory(){
       this.session = HibernateUtil.getSession();
   }
   public void beginTransaction(){
       this.transaction = this.session.beginTransaction();
   }
   public void commit(){
       this.transaction.commit();
       this.transaction = null;
   }
   public boolean hasTransaction(){
       return this.transaction != null; 
   }
   public void rollback(){
       this.transaction.rollback();
       this.transaction = null;
   }
   public void close(){
       this.session.close();
   }
   public GrupoDao getGrupoDao(){
       return new GrupoDao(session);
   }
   public ProdutoDao getProdutoDao(){
       return new ProdutoDao(session);
   }
}
